// @include "../../../scripts/spket.js"

validator = {};

validator.USER_INVALID = "Invalid user data.";
validator.USER_NAME_EMPTY = "Name cannot be empty.";
validator.USER_NAME_TOO_LONG = "Name cannot be longer than 50.";
validator.USER_NAME_FORMAT = "Name format is not conrrect.";
validator.USER_DESC_EMPTY = "Description cannot be empty.";
validator.USER_DESC_TOO_LONG = "Description cannot be longer than 50.";

validator.validateUser = function(user) {
	if (typeof user.name !== "string"
			|| typeof user.desc !== "string") {
		return { success: false, error: validator.USER_INVALID };
	}

	if (!user.name) {
		return { success: false, error: validator.USER_NAME_EMPTY };
	}

	if (user.name.length > 50) {
		return { success: false, error: validator.USER_NAME_TOO_LONG };
	}

	if (!/^[A-z][A-z0-9._]*$/.test(user.name)) {
		return { success: false, error: validator.USER_NAME_FORMAT };
	}

	if (!user.desc) {
		return { success: false, error: validator.USER_DESC_EMPTY };
	}

	if (user.desc.length > 50) {
		return { success: false, error: validator.USER_DESC_TOO_LONG };
	}

	var data = { name: user.name, desc: user.desc }
	return { success: true, data: data };
}
